package Text1;

import java.util.Scanner;

import java.util.Arrays;

public class Main {

    public static void selecisort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            int min = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[min]) {
                    min = j;
                }
            }
            swap(arr, i, min);
        }
    }

    public static void swap(int[] arr, int x, int y) {
        int tmp = arr[x];
        arr[x] = arr[y];
        arr[y] = tmp;
    }

    public static void main1(String[] args) {
        int[] arr = {5, -1, 0, 99, 77};
        selecisort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public void bubblesort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            boolean flag = false;
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] < arr[j + 1]) {
                    flag = true;
                    swap(arr, j, j + 1);
                }
            }
            if (flag == false) {
                break;
            }
        }
    }

    public void qsort(int[] arr, int l, int r) {
        if (l >= r) {
            return;
        }
        int x = arr[l + r >> 1], i = l - 1, j = r + 1;
        while (i < j) {
            do {
                i++;
            } while (arr[i] < x);
            do {
                j--;
            } while (arr[j] > x);
            if (i < j) {
                swap(arr, i, j);
            }
        }

        qsort(arr, l, j);
        qsort(arr, j + 1, r);
    }


    private static void msort(int[] q, int l, int r) {
        if (l >= r) {
            return;
        }
        int mid = l + r >> 1;
        msort(q, l, mid);
        msort(q, mid + 1, r);
        int k = 0, i = l, j = mid + 1;
        int[] tmp = new int[r - l + 1];
        while (i <= mid && j <= r) {
            if (q[i] < q[j]) {
                tmp[k++] = q[i++];
            } else {
                tmp[k++] = q[j++];
            }
        }
        while (i <= mid) {
            tmp[k++] = q[i++];
        }
        while (j <= r) {
            tmp[k++] = q[j++];
        }
        for (int m = 0; m < tmp.length; m++) {
            q[m + l] = tmp[m];
        }
    }

    public static int search(int[] arr, int key) {
        int i = 0;
        for (i = arr.length - 1;arr[i]!=key; --i) ;
        return i;
    }

    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            arr[i] = scanner.nextInt();
        }
        int key = scanner.nextInt();
        arr[0] = key;
        int idex = search(arr, key);
        System.out.printf("第%d个", idex);
    }
}
